import { createStore } from "vuex";

export default createStore({
  state() {
    return {
      user: {
        username: '',
        ip: null,
        id: -1,
        nickname: null,
        avatar: null,
        token: null,
        open: false,
        interval: 5,
        led:0,
      },
    };
  },
  getters: {},
  mutations: {
    setUser(state, username) {
      state.user.username = username;
      //   state.user.id=user.uid
      //   state.user.avatar=user.avatarUrl
      //   state.user.nickname=user.nickname
      //   state.user.token=user.token
    },
    setUserIP(state, ip) {
      state.user.ip = ip;
    },
    setUserOpen(state, open) {
      state.user.open = open;
    },
    setUserInterval(state, interval) {
      state.user.interval = interval;
    },
    setUserLED(state, led) {
      state.user.led = led;
    },
    clearUser(state) {
      state.user.id = -1;
      state.user.avatar = null;
      state.user.nickname = null;
      state.user.token = null;
    },
    updateUser(state, user) {
      // console.log(user.avatarUrl)
      // console.log(user.nickname)
      state.user.avatar = user.avatarUrl;
      state.user.nickname = user.nickname;
    },
  },
  actions: {},
  modules: {},
});
